#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
string s;
map<char, int>mp;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> s;
		sort(s.begin(), s.end());
		mp.clear();
		int cnt = 0;
		for (int i = 0; i < s.size(); i++) {
			if (!mp[s[i]]) {
				mp[s[i]] = 1;
				cnt++;
			}
		}
		if (cnt == 2) {
			if (s[0] == s[1] && s[1] == s[2] && s[2] != s[3]) cout << "Yes" << endl;
			else if (s[0] != s[1] && s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}